package com.fwj.auth.strategy;

import com.alibaba.fastjson.JSONObject;
import com.fwj.auth.entity.user.UserExtendAccount;
import com.fwj.auth.model.BindInfo;
import com.fwj.auth.strategy.impl.RegisterStrategyImpl;

/**
 * @Author: fwj
 * @Data: 2022/5/4 6:41
 * @Version 1.0
 * @Description:
 */


public enum RegisterStrategy {
    // 注册方式策略枚举
    /**
     * 手机注册
     */
    PHONE("phone", RegisterStrategyImpl.PHONE),
    /**
     * 邮箱注册
     */
    EMAIL("mail", RegisterStrategyImpl.EMAIL),
    /**
     * 微信授权注册
     */
    WECHAT("wechat", RegisterStrategyImpl.WECHAT),
    /**
     * QQ授权注册
     */
    QQ("qq", RegisterStrategyImpl.QQ),
    /**
     * 微博授权注册
     */
    MICRO_BLOG("microBlog", RegisterStrategyImpl.MICRO_BLOG),
    ;

    private final String strategy;

    private final RegisterStrategyImpl registerStrategyImpl;

    RegisterStrategy(String strategy, RegisterStrategyImpl registerStrategyImpl) {
        this.strategy = strategy;
        this.registerStrategyImpl = registerStrategyImpl;
    }

    //获取策略
    public String getStrategy() {
        return strategy;
    }

    //策略执行
    public void execStrategy(JSONObject jsonObject){
        registerStrategyImpl.exec(jsonObject);
    }

    //匹配策略，可优化
    public static RegisterStrategy matchStrategy(String strategy) {
        for (RegisterStrategy registerStrategy : RegisterStrategy.values()) {
            //返回匹配成功的策略
            if (registerStrategy.getStrategy().equals(strategy)) {
                return registerStrategy;
            }
        }
        return null;
    }
}
